//
//  ViewController.swift
//  CALayer动画合集 位置动画
//
//  Created by app on 2017/4/13.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var loginButton:UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loginButton = UIButton()
        loginButton.frame  = CGRect(x: 20, y: 230, width: view.frame.width - 40, height: 40)
        loginButton.backgroundColor = UIColor.red
        loginButton.setTitle("11", for: .normal)
        view.addSubview(loginButton)
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // 位置
//        let animation:CABasicAnimation = CABasicAnimation()
//        animation.keyPath = "position"
//        let positionX:CGFloat = loginButton.frame.origin.x + 0.5 * loginButton.frame.size.width
//        
//        let postionY:CGFloat = loginButton.frame.size.height + 100
//        
//        animation.toValue = NSValue(cgPoint: CGPoint(x: positionX, y: postionY))
//        
//        animation.duration = 1
//        
//        animation.fillMode = kCAFillModeForwards
//        
//        animation.isRemovedOnCompletion = false
//        
//        loginButton.layer.add(animation, forKey: nil)
        
        // 缩放
        let animation:CABasicAnimation = CABasicAnimation()
        animation.keyPath = "transform.scale.x"
        animation.fromValue = 1
        animation.toValue = 0.8
        animation.duration = 2
        animation.fillMode = kCAFillModeForwards
        animation.isRemovedOnCompletion = true
        loginButton.layer.add(animation, forKey: nil)
    }
}

